
import Foundation

class DMCCUser {
    var id: Int64 = 0
    var userId = ""
    var isNull = false
    var name = ""
    var portrait = ""
    @objc var alias = ""
    var describes = ""
    var content = ""
    var state = 0
    var timestamp: Int64 = 0
    var role = ""
    var nft = ""
    var friendAlias = ""
    var uiData:Any = ""
    var isSelect = Bool()
    var isNotSelect = Bool()

    
    
    
    func getDisplayName() ->String {
        if !friendAlias.isEmpty {return friendAlias}
        if !alias.isEmpty {return alias}
        return name
    }
    func isAllowTemporaryChat()->Bool {
        guard !describes.isEmpty, let json = OsnUtils.toJson(describes) else {
            return false
        }
        let res = json["AllowTemporaryChat"]
        return  res as! String == "yes" ? true : false

    }
    
    func getAlias () -> String {
        guard let f = gosnFriend.getFriendInfo(userId) else {
            if alias.count > 0 {
               return alias
           }
           return name
        }
        if f.alias.count > 0 {
            return f.alias
        }else if alias.count > 0 {
            return alias
        }
        return name
        
    }
    
    func getDescribe(forKey key: String) -> String? {
        guard !describes.isEmpty else {
                return nil
            }

        if let json = describes.toJson(),
               let value = json[key] as? String {
                return value
            }

            return nil
    }
    
    func getNft() -> String? {
            guard let nftUrl = getDescribe(forKey: "nft"), !nftUrl.isEmpty else {
                return ""
            }

            if nftUrl.hasPrefix("http") {
                return nftUrl
            }

            return ""
        }
    
}
